package com.xjy.web.controller.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.ReportMaterialVo;
import com.xjy.system.domain.bo.ReportMaterialQueryBo;
import com.xjy.system.domain.bo.ReportMaterialAddBo;
import com.xjy.system.domain.bo.ReportMaterialEditBo;
import com.xjy.system.service.IReportMaterialService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物料数据汇总报表Controller
 *
 * @author zc
 * @date 2022-03-21
 */
@Api(value = "物料数据汇总报表控制器", tags = {"物料数据汇总报表管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/ReportMaterial")
public class ReportMaterialController extends BaseController {

	private final IReportMaterialService iReportMaterialService;

	/**
	 * 查询物料数据汇总报表列表
	 */
	@ApiOperation("查询物料数据汇总报表列表")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:list')")
	@GetMapping("/list")
	public TableDataInfo<ReportMaterialVo> list(@Validated ReportMaterialQueryBo bo) {
		return iReportMaterialService.queryPageList(bo);
	}

	/**
	 * 导出物料数据汇总报表列表
	 */
	@ApiOperation("导出物料数据汇总报表列表")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:export')")
	@Log(title = "物料数据汇总报表", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<ReportMaterialVo> export(@Validated ReportMaterialQueryBo bo) {
		List<ReportMaterialVo> list = iReportMaterialService.queryList(bo);
		ExcelUtil<ReportMaterialVo> util = new ExcelUtil<ReportMaterialVo>(ReportMaterialVo.class);
		return util.exportExcel(list, "物料数据汇总报表");
	}

	/**
	 * 获取物料数据汇总报表详细信息
	 */
	@ApiOperation("获取物料数据汇总报表详细信息")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:query')")
	@GetMapping("/{mindate}")
	public AjaxResult<ReportMaterialVo> getInfo(@NotNull(message = "主键不能为空")
												@PathVariable("mindate") String mindate) {
		return AjaxResult.success(iReportMaterialService.queryById(mindate));
	}

	/**
	 * 新增物料数据汇总报表
	 */
	@ApiOperation("新增物料数据汇总报表")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:add')")
	@Log(title = "物料数据汇总报表", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody ReportMaterialAddBo bo) {
		return toAjax(iReportMaterialService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改物料数据汇总报表
	 */
	@ApiOperation("修改物料数据汇总报表")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:edit')")
	@Log(title = "物料数据汇总报表", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody ReportMaterialEditBo bo) {
		return toAjax(iReportMaterialService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除物料数据汇总报表
	 */
	@ApiOperation("删除物料数据汇总报表")
	@PreAuthorize("@ss.hasPermi('system:ReportMaterial:remove')")
	@Log(title = "物料数据汇总报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mindates}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable String[] mindates) {
		return toAjax(iReportMaterialService.deleteWithValidByIds(Arrays.asList(mindates), true) ? 1 : 0);
	}
}
